package com.umer.pinban.scan.adapter;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.common.ui.recycleview.PullLoadMoreRecyclerView;
import com.common.ui.recycleview.adapter.RecyclerviewBasicPageAdapterTwo;
import com.common.ui.recycleview.base.ViewHolder;
import com.common.ui.recycleview.listener.DataStateListener;
import com.common.ui.recycleview.listener.OptListener;
import com.common.utils.Constants;
import com.facebook.drawee.view.SimpleDraweeView;
import com.umer.pinban.R;
import com.umer.pinban.bean.customer.CommodityListBean;

public class SelectJiaGouProjectAdapter extends RecyclerviewBasicPageAdapterTwo<CommodityListBean> {

    private OptListener optListener;

    public SelectJiaGouProjectAdapter(Context context, int layoutId) {
        super(context, layoutId);
    }

    public SelectJiaGouProjectAdapter(Context context, int layoutId,
                                      PullLoadMoreRecyclerView pullLoadMoreRecyclerView,
                                      DataStateListener dataStateListener, OptListener optListener) {
        super(context, layoutId, pullLoadMoreRecyclerView, dataStateListener);
        this.optListener = optListener;
    }

    @Override
    public void convert(ViewHolder holder, CommodityListBean commodityListBean, final int position) {
        SimpleDraweeView simpleDraweeView = holder.getView(R.id.iv_jiagou);
        TextView tv1 =  holder.getView(R.id.tv1);
        TextView tv_jian_jiagou =  holder.getView(R.id.tv_jian_jiagou);
        TextView tv_jia_jiagou =  holder.getView(R.id.tv_jia_jiagou);
        TextView tv_result_jiagou =  holder.getView(R.id.tv_result_jiagou);
        tv1.setText(commodityListBean.getName());
        tv_result_jiagou.setText(""+commodityListBean.getCount());
        String path = commodityListBean.getFilePath();
        if(!TextUtils.isEmpty(path)){
            Uri uri = Uri.parse(Constants.IP_PORT_DEFAULT_PICTURE+path);
            simpleDraweeView.setImageURI(uri);
        }else {
            Uri uri = Uri.parse("");
            simpleDraweeView.setImageURI(uri);
        }
        tv_jian_jiagou.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,position);
            }
        });
        tv_jia_jiagou.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,position);
            }
        });
    }
}
